package com.itao.poi.tl;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.config.ConfigureBuilder;
import com.deepoove.poi.util.PoitlIOUtils;
import com.itao.poi.tl.util.ResourceUtil;

import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 区块标签{{?lebalName}}{{/lebalName}}
 *
 * @author sjt
 * @Date 2024/10/10 8:54
 */
public class SectionsLebal {

    public static void main(String[] args) throws Exception {
        // 如果标签内要使用运算符，需要开启Spring表达式
        ConfigureBuilder builder = Configure.builder().useSpringEL();
        XWPFTemplate template = XWPFTemplate.compile(ResourceUtil.getDocxPath("sections_template.docx"), builder.build())
                .render(new HashMap<String, Object>() {
                            {
                                put("announce", false);
                                put("person", Map.of("name", "Sayi"));
                                put("songs", List.of(
                                                Map.of("name", "Memories"),
                                                Map.of("name", "Sugar"),
                                                Map.of("name", "Last Dance")
                                        )
                                );
                                put("produces", List.of("application/json", "application/xml"));
                            }
                        }
                );
        FileOutputStream fos = new FileOutputStream(ResourceUtil.getDocxOutPath("sections_template.docx"));
        template.writeAndClose(fos);
        PoitlIOUtils.closeQuietlyMulti(template, fos);
    }
}
